package com.abocode.aichat.utils;


import org.apache.commons.beanutils.BeanUtils;

import java.util.Map;

public class HappBeanUtils  extends BeanUtils {
    public static Object mapToObject(Map<String, Object> map, Class<?> beanClass)  {
        if (map == null){
            return null;
        }
        String message;
        try {
            Object obj  = beanClass.newInstance();
            BeanUtils.populate(obj, map);
            return obj;
        } catch (Exception e) {
            message=e.getMessage();
        }
        throw  new RuntimeException(message);
    }

    public static Map<?, ?> objectToMap(Object obj) {
        if(obj == null)
            return null;
        return new org.apache.commons.beanutils.BeanMap(obj);
    }
}
